#!/usr/bin/env python
# vim: set fileencoding=UTF-8 :

# ------------------------------------------------------------
# ::                        WIGA-SOFT                       ::
# ------------------------------------------------------------
# models.py
# Database structure using Django Model wrapper
# Created by: Vycas
# Version: 1.0
# ------------------------------------------------------------

from django.db import models
from django.contrib.auth.models import User


class Employee(models.Model):
    id = models.OneToOneField(User, primary_key=True)
    department = models.ForeignKey('Department', verbose_name='Skyrius', null=True)

    class Meta:
        verbose_name = 'Darbuotojas'
        verbose_name_plural = 'Darbuotojai'

    def __unicode__(self):
        return self.id.username


class Project(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField('Pavadinimas', max_length=255, null=True, blank=True)
    manager = models.ForeignKey(Employee, verbose_name='Projekto vadovas', null=True)

    class Meta:
        verbose_name = 'Projektas'
        verbose_name_plural = 'Projektai'

    def __unicode__(self):
        return self.name or str(self.id)


class Department(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField('Pavadinimas', max_length=255, null=True, blank=True)
    manager = models.ForeignKey(Employee, verbose_name='Skyriaus vadovas', related_name='manages')

    class Meta:
        verbose_name = 'Skyrius'
        verbose_name_plural = 'Skyriai'

    def __unicode__(self):
        return self.name or str(self.id)


class Task(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField('Pavadinimas', max_length=255, null=True, blank=True)
    project = models.ForeignKey(Project, verbose_name='Projektas', db_index=True)
    employee = models.ForeignKey(Employee, verbose_name='Darbuotojas')
    date = models.DateField('Data')
    workhours = models.IntegerField('Išdirbtos valandos')

    class Meta:
        verbose_name = 'Užduotis'
        verbose_name_plural = 'Užduotys'

    def __unicode__(self):
        return self.name or str(self.id)


class Budget(models.Model):
    id = models.AutoField(primary_key=True)
    project = models.ForeignKey(Project, verbose_name='Projektas', db_index=True)
    date = models.DateField('Data')
    workhours = models.IntegerField('Skirtas biudžetas')

    class Meta:
        verbose_name = 'Biudžetas'
        verbose_name_plural = 'Biudžetai'

    def __unicode__(self):
        return str(self.id)

